home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / all java / quicktime for java / music / src / notestonetest.java
Encoding:
Java Source  |  2000-06-23  |  1.8 KB  |  60 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import quicktime.*;
  9. import quicktime.std.music.*;
  10. import quicktime.std.StdQTException;
  11. import quicktime.util.QTUtils;
  12.  
  13. public class NotesToneTest implements Errors {
  14.     public static void main (String[] args) {
  15.         try {
  16.             System.out.println ("Starting QTMA Test");
  17.             QTSession.open();
  18.             
  19.             // A NoteAllocator is required for using NoteChannels
  20.             // However QTJava provides a default NA:
  21.             //    NoteAllocator na = NoteAllocator.getDefault();
  22.             // and this is used for the TD/NR and NC constructors if the
  23.             // application does not provide one.
  24.             
  25.             System.out.println ("Pick Instrument:");
  26.             ToneDescription td = new ToneDescription ();
  27.                 //print out an uninitialized ToneDescription
  28.             System.out.println (td);
  29.             
  30.             try {
  31.                 // Have the user choose an instrument and print out the choice
  32.                 td.pickInstrument (NoteAllocator.getDefault(), "Choose an Instrument...", 0);
  33.                 System.out.println (td);
  34.             } catch (StdQTException e) {
  35.                 if (e.errorCode() != userCanceledErr) return;
  36.             }
  37.                 
  38.                 // Make a Tone Description using GMIDI inst. no. 25
  39.             System.out.println ("StuffTone:25");
  40.             td = new ToneDescription (25);
  41.             System.out.println (td);
  42.  
  43.                 // Play a note (60) at maximum velocity (127) for 2000msecs then turn it off.
  44.             System.out.println ("PlayNote:Inst,25, Note,60");
  45.             NoteChannel nc = new NoteChannel(new NoteRequest(td));
  46.             nc.playNote (60, 127);
  47.                 try { Thread.sleep (2000); } 
  48.                 catch (InterruptedException e) { e.printStackTrace(); }
  49.             nc.playNote (60, 0);
  50.         }
  51.         catch (QTException qte) {
  52.             qte.printStackTrace();
  53.         }
  54.         finally {
  55.             System.out.println ("Finished QTMA Test");
  56.             QTSession.close();
  57.         }
  58.     }
  59. }
  60.